#include "RealtimeProcess.h"
namespace re{
	namespace real{

DWORD WINAPI RealtimeProcess::BeginThread(LPVOID lParam)
{
	RealtimeProcess * pProcess = reinterpret_cast<RealtimeProcess*>(lParam);
	pProcess->StartProcess();
	return 0;
}

void RealtimeProcess::Run()
{
	bool run = true;
	while(run)
	{
		boost::mutex::scoped_lock lock(m_mutex);
		if(m_is_running)
		{
			lock.unlock();
			VUpdate();
		}
		lock.lock();
		run = m_thread_created;
		lock.unlock();
	}
}
void RealtimeProcess::LaunchProcess()
{
	boost::mutex::scoped_lock lock(m_mutex);
	if(!m_thread_created)
	{
		m_thread_created = true;
		m_Thread = CreateThread(0,0,&BeginThread, this, 0, 0);
	}
}
void RealtimeProcess::StartProcess()
{
	boost::mutex::scoped_lock lock(m_mutex);
	m_is_running = true;
	VResumed();
}
void RealtimeProcess::PauseProcess()
{
	boost::mutex::scoped_lock lock(m_mutex);
	m_is_running = false;
	VPaused();
}
void RealtimeProcess::KillProcess()
{
	boost::mutex::scoped_lock lock(m_mutex);
	if(m_thread_created)
	{
		VPaused();
		CloseHandle(m_Thread);
	}
}



void RealtimeListener::VHandleEvent(EventDataPtr data)
{
	m_queue.push(data->VMakeCopy());
}




}
}